<?php

/**
 *  List all emedia items available in the course
 *
 * @copyright (c) 2012 University of Geneva
 * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
 * @author Laurent Opprecht laurent@opprecht.info
 */
require('../../config.php');
require_once($CFG->dirroot . '/mod/emedia/lib.php');
require_once($CFG->dirroot . '/mod/emedia/lib/emedia_table.class.php');

$id = required_param('id', PARAM_INT); // course id
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);

require_course_login($course, true);
$PAGE->set_pagelayout('incourse');

add_to_log($course->id, 'emedia', 'view all', "index.php?id=$course->id", '');

$modulenameplural = EMedia::get_string('modulenameplural');

$PAGE->set_url('/mod/emedia/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname . ': ' . $modulenameplural);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($modulenameplural);
echo $OUTPUT->header();

$items = EMediaStore::select_by_course($course);

if (empty($items))
{
    notice(get_string('thereareno', 'moodle', $modulenameplural), "$CFG->wwwroot/course/view.php?id=$course->id");
    exit;
}

EMediaTable::create()->display($course, $items);

echo $OUTPUT->footer();
